package com.hmy.cornpestdet.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class PolygonArea {
    private int uid;
    private String points;
    private int editable;
    private String fillColor;
    private String addDate;

    public List<MyPoint> fromPointsStrGetPointsList(){
        List<MyPoint> pointList = new ArrayList<>();
        String coordinates = points.replace("POLYGON((", "").replace("))", "");
        String[] coordinatePairs = coordinates.split(",");
        for (String pair : coordinatePairs) {
            String[] lngLat = pair.split(" ");
            if (lngLat.length == 2) {
                double lng = Double.parseDouble(lngLat[0]);
                double lat = Double.parseDouble(lngLat[1]);
                pointList.add(new MyPoint(lng, lat));
            }
        }
        return pointList;
    }

}
